package vip.xiaonuo.smzq.modular.kcl.controller;

import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.smzq.modular.kcl.entity.Zlsc;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.Zlxqcx;
import vip.xiaonuo.smzq.modular.kcl.service.IZlscService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 资料上传
 *
 * @author sqq
 * @since 2024-03-13
 */
@Api(tags = "资料上传")
@RestController
@RequestMapping("/kcl/zlsc")
@Validated
public class ZlscController {

    @Resource
    private IZlscService iZlscService;

    /**
     * 添加资料上传
     */
    @ApiOperation("添加资料上传")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Zlsc zlsc) {
        iZlscService.save(zlsc);
        return CommonResult.ok();
    }

    /**
     * 删除资料上传
     */
    @ApiOperation("删除资料上传")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iZlscService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑资料上传
     */
    @ApiOperation("编辑资料上传")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Zlsc zlsc) {
        iZlscService.updateById(zlsc);
        return CommonResult.ok();
    }

    /**
     * 资料上传分页查询
     */
    @ApiOperation("资料上传分页查询")
    @GetMapping("/list")
    public CommonResult<Page<Zlsc>> page() {
        return CommonResult.data(iZlscService.page(new Zlsc()));
    }


    /**
     * 资料上传
     */
    @ApiOperation("资料上传")
    @PostMapping("/fileUpload")
    public CommonResult<List<Zlxqcx>> fileUpload(
            @RequestPart("files") List<MultipartFile> files,
            @Validated  Zlsc zlsc
    ) {
        return CommonResult.data(iZlscService.fileUpload(files,zlsc));
    }

    @ApiOperation("预览")
    @GetMapping("/preview")
    public void preview(String path) {
        iZlscService.fileShow(path);
    }



}
